package com.dahong.cloud.server.domain.converter;

import static com.lambda.cloud.core.Constants.GSON;

import com.dahong.cloud.server.domain.dto.UserCreateDTO;
import com.dahong.cloud.server.domain.entity.UserEntity;
import com.lambda.cloud.core.convert.BaseConverter;
import java.util.Map;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

public interface UserCreateConverter extends BaseConverter<UserCreateDTO, UserEntity> {

    // DTO -> Entity
    @Mapping(target = "extend", source = "extend", qualifiedByName = "mapToStr")
    @Override
    UserEntity convertTo(UserCreateDTO source);

    @Named("mapToStr")
    default String mapToStr(Map<String, String> map) {
        if (map == null) return null;
        return GSON.toJson(map);
    }
    //
    //    // Entity -> DTO
    //    @Mapping(target = "extend", source = "extend", qualifiedByName = "stringToMap")
    //    @Override
    //    UserCreateDTO convertFrom(UserEntity source);
    //
    //    @Named("stringToMap")
    //    default Map<String, String> stringToMap(String json) {
    //        if (json == null || json.isBlank()) {
    //            return null;
    //        }
    //        return GSON.fromJson(json, new TypeToken<Map<String, String>>() {}.getType());
    //    }
}
